﻿using System;
using System.Data;
using System.Configuration;
using System.Xml;
using System.IO;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;

/// <summary>
/// Summary description for ExecuteXML
/// </summary>
namespace BCDataCenter
{
    public class ExecuteXML
    {
        public ExecuteXML()
        {
            //
            // TODO: Add constructor logic here
            //
        }
        public void InsertNodeInmast(string itemkey, string description)
        {
            XmlDocument xmldoc = new XmlDocument();
            xmldoc.Load("~/DataXML/inmast.xml");
            // New XML Element Created
            XmlElement newcatalogentry = xmldoc.CreateElement("row");

            // New Attribute Created
            XmlAttribute newcatalogattr = xmldoc.CreateAttribute("itemkey");

            // Value given for the new attribute
            newcatalogattr.Value = itemkey;

            // New Attribute Created
            XmlAttribute newcatalogattr1 = xmldoc.CreateAttribute("description");

            // Value given for the new attribute
            newcatalogattr1.Value = description;


            // Attach the attribute to the XML element
            newcatalogentry.SetAttributeNode(newcatalogattr);
            newcatalogentry.SetAttributeNode(newcatalogattr1);



            // New XML element inserted into the document
            xmldoc.DocumentElement.InsertAfter(newcatalogentry, xmldoc.DocumentElement.LastChild);
            // An instance of FileStream class created
            

            //save
            xmldoc.Save("~/DataXML/inmast.xml");
        }
        public void UpdateInmast(string itemkey, string description)
        {
            XmlDocument xmldoc = new XmlDocument();
            xmldoc.Load("~/DataXML/inmast.xml");
            XmlNode t = xmldoc.SelectSingleNode("/product/row[@itemkey='" + itemkey + "']");
            t.Attributes["description"].InnerText = description;
            xmldoc.Save("~/DataXML/inmast.xml");
        }
        public void xmldoc(string itemkey)
        {
            XmlDocument xmldoc = new XmlDocument();
            xmldoc.Load("~/DataXML/inmast.xml");
            XmlNode t = xmldoc.SelectSingleNode("/product/row[@itemkey='" + itemkey + "']");
            t.ParentNode.RemoveChild(t);
            xmldoc.Save("~/DataXML/inmast.xml");
        }
    }
}
